/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleship_server;

/**
 *
 * @author omar
 */
public class Game {

    Coordinate[][] player1Array;
    Coordinate[][] player2Array;

    private int timeElapsed = 0;
    private int timePlayed = 0;
    private int timeWait = 0;
    private int timeToSet = 0;
    private int gameId = 0;

    private Player player1 = null;
    private Player player2 = null;

    private Player winner = null;

    public Game() {
        player1Array = new Coordinate[10][10];
        player2Array = new Coordinate[10][10];
        inicializador();

    }

    private void inicializador() {
        for (int x = 0; x < 10; x++) {
            for (int y = 0; y < 10; y++) {
                player1Array[x][y] = new Coordinate();
                player2Array[x][y] = new Coordinate();
            }
        }
    }

    public boolean receivesHit(int player, int x, int y) {
        return (player == 1 ? player2Array[x][y].receivesHit() : player1Array[x][y].receivesHit());
    }

    /* Poner el inicio y fin como constantes */
    /* Recibe muchos atributos */
    public void setShip(int player, int shipType, int startx, int starty, int endx, int endy) {
        if ((startx != endx ? true : false)) {
            for (int i = (startx - 1); i < (endx - 1); i++) {
                if (((player == 1) ? player1Array : player2Array)[i][(starty - 1)].isAvailable()) {
                    ((player == 1) ? player1Array : player2Array)[i][(starty - 1)].placeShip(shipType);
                }
            }
        } else {
            for (int i = (starty - 1); i < (endy - 1); i++) {
                if (((player == 1) ? player1Array : player2Array)[(startx - 1)][i].isAvailable()) {
                    ((player == 1) ? player1Array : player2Array)[i][(starty - 1)].placeShip(shipType);
                }
            }
        }
    }
    
    
    
}
